<?php include("../../includes/includes.php"); ?>
<?php
connect($config);
$partyTwo = $_POST['partyTwo'];
$loggedInTeam = getLoggedInTeam();
$leagueId = getLeagueId();

$partyTwoPicks = getPicks($partyTwo, false, $leagueId);
$partyTwoPlayers = getDraftedPlayers($partyTwo);

$partyTwoTeam = getTeamById($partyTwo, false);

$partyOnePicks = getPicks($loggedInTeam->id, false, $leagueId);
$partyOnePlayers = getDraftedPlayers($loggedInTeam->id);
$result = "<form action='../trades/proposeTrade.php' method='post' target='hiddenFrame'><input type='hidden' name='partyTwo' value='$partyTwo'><table width='30%' align='center'>";
$result .= "<tr><td width='40%'><table><tr><td><b>" . $loggedInTeam->coachName . "</b></td></tr><tr><td><b>Players</b></td></tr>";
$result .= "<tr><td><select id='partyOnePlayers' size='10' multiple>";
$count = count($partyOnePlayers);
for ($i = 0; $i < $count; $i++) {
	$result .= "<option value='" . $partyOnePlayers[$i]->player->id . "'>" . $partyOnePlayers[$i]->player->getDescription() . "</option>";  
}
$result .= getSpacerOption() . "</select></td></tr><tr><td><b>Picks</b></td></tr><tr><td><select id='partyOnePicks' size='10' multiple style='width: 80'>";
$count = count($partyOnePicks);
for ($i = 0; $i < $count; $i++) {
	$result .= "<option value='" . $partyOnePicks[$i]->pickNumber . "'>#" . $partyOnePicks[$i]->pickNumber . "</option>";  
}
$result .= getSpacerOption() . "</select></td></tr><tr><td><b>Receives</b><br><div id='partyOneGets'></div></td></tr></table></td>";

$result .= "<td width='20%'><table><tr><td align='center'><br><br><br><br><br><br><br><input type='button' value='Trade to -->' onclick='tradeTo(this.form)'></td></tr><tr><td><br><br></td></tr><tr><td align='center'><input type='button' value='<-- Trade for' onclick='tradeFor(this.form)'></td></tr></table></td>";

$result .= "<td width='40%'><table><tr><td><b>" . $partyTwoTeam->coachName . "</b></td></tr><tr><td><b>Players</b></td></tr>";
$result .= "<tr><td><select id='partyTwoPlayers' size='10' multiple>";
$count = count($partyTwoPlayers);
for ($i = 0; $i < $count; $i++) {
	$result .= "<option value='" . $partyTwoPlayers[$i]->player->id . "'>" . $partyTwoPlayers[$i]->player->getDescription() . "</option>";  
}
$result .= getSpacerOption() . "</select></td></tr><tr><td><b>Picks</b></td></tr><tr><td><select id='partyTwoPicks' size='10' multiple>";
$count = count($partyTwoPicks);
for ($i = 0; $i < $count; $i++) {
	$result .= "<option value='" . $partyTwoPicks[$i]->pickNumber . "'>#" . $partyTwoPicks[$i]->pickNumber . "</option>";  
}
$result .= getSpacerOption() . "</select></td></tr><tr><td><b>Receives</b><br><div id='partyTwoGets'></div></td></tr></table></td></tr>";
$result .= "<tr><td colspan='2'><input type='hidden' name='partyOneReceives'><input type='hidden' name='partyTwoReceives'><input type='button' value='Clear' onClick='clearTrade()' class='buttonStyle'>&nbsp;<input type='button' value='Cancel Trade' onClick='cancelTrade()' class='buttonStyle'>&nbsp;<input type='button' value='Propose Trade' onClick='validateTrade(this.form)' class='buttonStyle'></td></tr></table></form><form id='cancelForm' name='cancelForm' action='../trades/cancelTrade.php' method='post' target='hiddenFrame'></form>";

mysql_close();
?>

<script>
var itemsInvolvedInTrades = Array(<?echo getItemsInvolvedInTrades($loggedInTeam->id)?>);
parent.document.getElementById("tradeDiv").innerHTML = "<?echo $result?>";
parent.document.getElementById("saveTradeHTML").value = "<?echo $result?>"; 
</script>


